package cn.itcast.service.company.impl;

import cn.itcast.dao.company.CompanyDao;
import cn.itcast.domain.Company;
import cn.itcast.domain.PageBean;
import cn.itcast.service.company.CompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service("companyService")
public class CompanyServiceImpl implements CompanyService {
    @Autowired
    private CompanyDao companyDao;
    @Override
    public PageBean findAll(int pageNum, int pageSize) {
        /*查询的总条数*/
       int count= companyDao.findCount();
       /*总页数*/
        int pagecount= (int) Math.ceil(count/pageSize)+1;
        /*查出的企业的信息*/
        List<Company> list = companyDao.findAll((pageNum-1)*pageSize,pageSize);
        PageBean pageBean = new PageBean();
        pageBean.setPageNum(pageNum);
        pageBean.setList(list);
        pageBean.setPageSize(pageSize);
        pageBean.setTotal(count);
        pageBean.setPages(pagecount);
        return pageBean;
    }
/*  保存新增的企业信息*/
    @Override
    public void save(Company company) {
        companyDao.save(company);
    }

    @Override
    public Company toUpdate(String id) {
        Company company=companyDao.toUpdate(id);
        return company;
    }
    /*修改企业的信息*/
    @Override
    public void updateCompany(Company company) {
        companyDao.updateCompany(company);
    }
/*删除企业的信息*/
    @Override
    public void deleteCompany(String id) {
    companyDao.deleteCompany(id);
    }
}
